/**
 * 生成 impala client bulkImport 所需的 columns 和 records
 * @param {*} sequelizeModel sequelize 模型对象
 * @param {*} dataList 数据数组
 */
function generateColsAndRecords (sequelizeModel, dataArr) {
  if (!dataArr.length) return { columns: [], records: [] }
  const rawAttributeNames = Object.keys(sequelizeModel.rawAttributes)
  const propertyNames = Object.keys(dataArr[0]).filter((i) => rawAttributeNames.includes(i))
  const columns = propertyNames.map((i) => sequelizeModel.rawAttributes[i].field)
  const records = dataArr.map((row) => propertyNames.map((col) => row[col]))
  return { columns, records }
}

module.exports = {
  generateColsAndRecords
}
